//
//  UIButton+Size.m
//  jobClient
//
//  Created by YL1001 on 2017/7/17.
//  Copyright © 2017年 YL1001. All rights reserved.
//

#import "UIButton+Size.h"

@implementation UIButton (Size)

+(CGSize)sizeOfLabelWithCustomMaxWidth:(CGFloat)width systemFontSize:(CGFloat)fontSize andFilledTextString:(NSString *)str {
    //    创建一个label
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, width, 0)];
    //    label 的文字
    label.text = str;
    //    label 的行数
    label.numberOfLines = 0;
    //    label的字体大小
    label.font = [UIFont systemFontOfSize:fontSize];
    //    让label通过文字设置size
    [label sizeToFit];
    //    获取label 的size
    CGSize size = label.frame.size;
    //    返回出去
    return size;
    
}


- (UIButton *)getNewButtonWithText:(NSString *)text {
    CGSize size = [text sizeNewWithFont:[UIFont systemFontOfSize:15 weight:UIFontWeightLight]];
    CGFloat width = size.width < 40 ? 40:size.width;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setExclusiveTouch:YES];
    button.frame = CGRectMake(0,0,width,40);
    button.backgroundColor = [UIColor clearColor];
    [button setImage:nil forState:UIControlStateNormal];
    [button setTitle:text forState:UIControlStateNormal];
    [button setTitleColor: EL_HexColor(0x222222) forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
    
    return button;
}

- (UIButton *)getNewButtonWithImageName:(NSString *)imageName {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setExclusiveTouch:YES];
    button.frame = CGRectMake(0,0,30,40);
    button.backgroundColor = [UIColor clearColor];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setTitle:@"" forState:UIControlStateNormal];
    [button setTitleColor:EL_HexColor(0x222222) forState:UIControlStateNormal];
    button.titleLabel.font =  [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
    return button;
}

@end
